/* eslint-disable @typescript-eslint/no-var-requires */
// eslint-disable-next-line @typescript-eslint/no-var-requires

const VueSSRClientPlugin = require('vue-server-renderer/client-plugin')
const VueSSRServerPlugin = require('vue-server-renderer/server-plugin')

const TARGET_NODE = process.env.WEBPACK_NODE === 'node';
const target = TARGET_NODE ? 'server' : 'client'

module.exports = {
  css: {
    extract: false //不抽离css
  },
  configureWebpack: {
    entry: `./src/entry-${target}.ts`,
    target: TARGET_NODE ? 'node' : 'web',
    node: TARGET_NODE ? {} : false,
    output: {
      libraryTarget: TARGET_NODE ? 'commonjs2' : undefined
    },
    plugins: [
      TARGET_NODE ? new VueSSRServerPlugin : new VueSSRClientPlugin()
    ]
  },
  chainWebpack(config){ 
    if(TARGET_NODE){
      config.plugins.delete('hmr'); // fix ssr hot update bug
      config.optimization.splitChunks(undefined);
    }
  }

}